<template>
  <div class="app-container">

    <el-input
      placeholder="输入关键字进行过滤"
      v-model="filterText">
    </el-input>
    <el-tree
      class="filter-tree"
      ref="subjectTree"
      :data="subjectList"
      :props="defaultProps"
      :filter-node-method="filterNode"
    >
    </el-tree>

  </div>
</template>

<script>

  import * as SubjectApi from '../../api/subject'

  export default {
    name: 'SubjectList',
    data: function() {

      return {

        subjectList:[],
        defaultProps: {
          children: 'children',
          label: 'title'
        },
        filterText:''
      }
    },
    created() {

      this.loadSubjectList();
    },
    methods:{

      async loadSubjectList(){

        this.subjectList = await SubjectApi.loadSubjectList(0);

      },
      filterNode(value, data) {
        if (!value) return true;
        return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1;
      }
    },
    watch: {
      filterText(val) {
        this.$refs.subjectTree.filter(val);
      }
    }
  }
</script>

<style scoped>


</style>
